﻿
using Irony.Compiler;

namespace IronLua.Ast {

	public class FunctionStatement : Statement {

		readonly Expression target;
		readonly FunctionExpression function;

		public Expression Target {
			get { return target; }
		}

		public FunctionExpression Function {
			get { return function; }
		}

		public override LuaNodeType NodeType {
			get { return LuaNodeType.FunctionStatement; }
		}

		public FunctionStatement (CompilerContext context, NonTerminal nonTerminal, SourceLocation location, AstNodeList childNodes)
			: base (context, nonTerminal, location, childNodes)
		{
			this.target = CreateTarget (childNodes [1]);
			this.function = new FunctionExpression (childNodes [childNodes.Count - 1]);
		}

		public FunctionStatement (CompilerContext context, NonTerminal nonTerminal, SourceLocation location, AstNodeList childNodes, Expression target)
			: base (context, nonTerminal, location, childNodes)
		{
			this.target = target;
			this.function = new FunctionExpression (childNodes [childNodes.Count - 1]);
		}

		Expression CreateTarget (AstNode node)
		{
			return null;
		}

		public override void Accept (ILuaAstVisitor visitor)
		{
			visitor.VisitFunctionStatement (this);
		}
	}
}
